package nl.tue.be.ds.duraark.bSDD.dump.alternatives;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nl.tue.be.ds.duraark.bSDD.dump.StorageUnitDumpCallable;

import org.codehaus.jackson.JsonNode;

public class DumpProcessor {

	private static final int MaxThreadNum = 2000;
	public static ExecutorService dumpStorageUnitCallablePool = Executors.newFixedThreadPool(MaxThreadNum);
	public static List<Future<Integer>> futureList = new ArrayList<Future<Integer>>();
	public static List<JsonNode> jsonConceptsList = new ArrayList<JsonNode>();	
	public static Integer dumpedNum = 0;
	
	/*public static void processDumpBySearchCallable(){
		if ((jsonConceptsList.size()%500)==0)
			try {
				processDump();
			} catch (InterruptedException e) {
				
				e.printStackTrace();
			} catch (ExecutionException e) {
				
				e.printStackTrace();
			}
	}*/
	
	public static void processDump() throws InterruptedException, ExecutionException{

		
		for (int i=0; i<jsonConceptsList.size(); i++){
			StorageUnitDumpCallable callable = new StorageUnitDumpCallable (jsonConceptsList.get(i));
			Future<Integer> future = dumpStorageUnitCallablePool.submit(callable);
			futureList.add(future);
		}
		
		for (int i=0; i<futureList.size(); i++){
			int dumpedNumPerfuture = 0;
			
			dumpedNumPerfuture = futureList.get(i).get();	
			dumpedNum = dumpedNum + dumpedNumPerfuture;
		}
		
	}
	
}
